package com.css.fxfzypg.modules.saresults.controller;

import com.css.fxfzypg.base.response.RestResponse;
import com.css.fxfzypg.modules.saresults.entity.DzqhApAsicMapEntity;
import com.css.fxfzypg.modules.saresults.entity.DzqhQpBasicMapEntity;
import com.css.fxfzypg.modules.saresults.param.ApTemporarySaveParam;
import com.css.fxfzypg.modules.saresults.service.QpResultsService;
import com.css.fxfzypg.modules.saresults.vo.SaResultsHlVo;
import com.css.fxfzypg.modules.saresults.vo.SaResultsIdVo;
import com.css.fxfzypg.modules.saresults.vo.SaResultsVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
 * 区评成果
 */
@RestController
@RequestMapping("qpResults")
@Slf4j
public class QpResultsController {

    @Autowired
    private QpResultsService qpResultsService;

    /**
     * 区评成果目录提交,保存，修改
     * @param saResultsVo
     * @return
     */
    @PostMapping("saveOrUpdateQpResults")
    public RestResponse saveOrUpdateQpResults(@RequestBody SaResultsVo saResultsVo) {
        return qpResultsService.saveOrUpdateQpResults(saResultsVo);
    }

    /**
     * 区评成果目录查询(修改回显)
     *
     * @param projectId
     * @return
     */
    @GetMapping("getQpResultsById")
    public RestResponse getSaResultsById(String projectId) {
        return qpResultsService.getSaResultsById(projectId);
    }

    /**
     * 区评成果目录项目信息删除
     *
     * @param
     * @return
     */
    @GetMapping("deleteQaResultsProject")
    public RestResponse deleteQaResultsProject(String projectId,String deleteReason,String reviewComments,String approvalStatus) {
        return qpResultsService.deleteQaResultsProject(projectId,deleteReason,reviewComments,approvalStatus);
    }

    /**
     * 区评成果数据导入
     *
     * @return
     */
    @PostMapping("importExcelQpResults")
    public RestResponse importExcelQpResults(MultipartFile file) {
        return qpResultsService.importExcelQpResults(file);
    }

    /**
     * 区评成果数据导出
     *
     * @return
     */
    @GetMapping("exportExcelQpResults")
    public void exportExcelQpResults(HttpServletResponse response, String projectId) {
        qpResultsService.exportExcelQpResults(response,projectId);
    }

    /**
     * 根据用户id查询未提交数据
     * @return
     */
    @GetMapping("notSubmitted")
    public RestResponse notSubmitted() {
        return qpResultsService.notSubmitted();
    }

    /**
     * 查询所有项目
     * @param
     * @return
     */
    @GetMapping("queryAllQpProject")
    public RestResponse queryAllQpProject() {
        return qpResultsService.queryAllQpProject();
    }

    /**
     * 区评成果目录项目信息分页查询
     * @param
     * @return
     */
    @GetMapping("getQpResultsProject")
    public RestResponse getQpResultsProject(DzqhQpBasicMapEntity qpBasicMapEntity, HttpServletRequest request,String geom) {
        return qpResultsService.getQpResultsProject(qpBasicMapEntity, request,geom);
    }

    /**
     * 区评成果目录孔位信息分页查询
     *
     * @return
     */
    @GetMapping("getQpResultsHl")
    public RestResponse getQpResultsHl(SaResultsHlVo saResultsHlVo, HttpServletRequest request,String geom) {
        return qpResultsService.getQpResultsHl(saResultsHlVo, request,geom);
    }

    /**
     * 新增或修改
     * @param param
     * @return
     */
    @PostMapping("saveOrUpdate")
    public RestResponse saveOrUpdate(@RequestBody ApTemporarySaveParam param){
        try {
            qpResultsService.saveOrUpdate(param);
            return RestResponse.succeed("成功!");
        } catch (Exception e) {
            log.error("post saveOrUpdate error:{}",e.getMessage(),e);
            return RestResponse.fail("失败!");
        }
    }
}
